package cn.wgoodq.study.MultiThreading;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

/**
 * Created by OuKyou on 2016/12/23.
 */
public class YieldThread extends Thread {
    private Logger logger = LogManager.getLogger(YieldThread.class);

    @Override
    public void run() {
        for (int i = 0; i < 100; i++) {
            logger.info(i);

            if (i == 20) {
                // yield()方法是指当前线程让出占用的CPU资源，然后和优先度大于等于自己优先度的线程一起再次抢夺CPU资源，谁抢到，谁执行。
                Thread.yield();
            }
        }
    }
}
